<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="入库单打印">
    <style media="print">
        @page {
            margin: 0mm; /* this affects the margin in the printer settings */
            size: landscape;
        }
    </style>

    <style>
        table{border-collapse: collapse;width: 100%}
        table td, table th{border: 1px solid #000000;}
        table td{padding:4px 0 4px 4px;}
        table td, table th{border: 1px solid #000000;}
        span,div,td,th{font-size:14px;}
    </style>

    <script>
        function printPage(data){
            let $printDiv = $("#printDiv");
            $printDiv.empty();

            genPage(data,$printDiv);

            setTimeout(function () {
                window.print();
            },100);
        }

        function genPage(data,$printDiv){
            genPrintDiv($printDiv, data.id, "入库单", data.no);
            let beforeList = [];
            let linkOrder = genLinOrder(data);

            if (linkOrder.linkUnit != "") {
                beforeList.push({label:"往来单位", content:linkOrder.linkUnit.name});
            } else {
                beforeList.push({label:"往来单位", content:""});
            }


            beforeList.push({label:"经办人", content:data.user.name});
            beforeList.push({width:180, label: "业务日期", content: GMTToDate(data.date)});
            beforeList.push({width:0,newLine: true,label:"入库仓库", content:data.houseVo.store.name + ">" + data.houseVo.name});


            beforeList.push({label:"物流单号", content:data.deliveryNo});
            beforeList.push({label:"支付运费", content:getPrice(data.deliveryAmt)});
            beforeList.push({label:"支付账户", content:data.settAccountVo.store.name + ">" + data.settAccountVo.name});
            beforeList.push({width:0,newLine: true,label:"物流公司", content:data.deliveryOrg});
            genPrintLine($('#'+data.id+' .before'), beforeList);

            let endList = [];
            endList.push({width:0, newLine: true,label:"备注", content:data.remark});
            endList.push({label:"制单人", content:data.makeUser.name});
            endList.push({width:0, label:"制单时间", content:data.makeTime});
            genPrintLine($('#'+data.id+' .end'), endList);

            let list=[];
            let index = 1;
            $.each(data.houseInGoodsVoList, function (i,d) {
                let vo = d.goodsVo;
                let data={};
                data.index = index++;
                data.no = vo.no;
                data.name = vo.name;
                data.norms = genGoodsNorm(vo.norms);
                data.number = vo.number;
                data.unit = genUnitName(vo.goodsUnitVoList, vo.unitId);
                data.remark = vo.remark==null ? "" :  vo.remark;
                list.push(data);
            });

            $.each(data.houseOutPacketVoList, function (i,d) {
                let data={};
                let vo = d;
                data.index = index++;
                data.no = vo.packetNo;
                data.name = vo.packetName;
                data.norms = "";
                data.number = vo.number;
                data.unit = "";
                data.remark = vo.remark == null ? "" : vo.remark;
                list.push(data);
            });

            genPrintTable($('#'+data.id+' .table'), ['序号','商品编号','商品名称','规格','数量','单位','备注'],list);
        }


        //获取关联单结构体
        function genLinOrder(d) {
            let vo = {};

            if (d.type ==1) {
                vo = d.inGoodsVo;
                vo.linkUnit = d.inGoodsVo.provider;
                return vo;
            }
            if (d.type ==2) {
                vo = d.refundVo;
                vo.linkUnit = d.refundVo.custom;
                return vo;
            }

            if (d.type ==3) {
                vo = d.goodsTransferVo;
                vo.linkUnit = "";
                return vo;
            }
            if (d.type ==4) {
                vo = d.borrowInVo;
                vo.linkUnit = d.borrowInVo.provider;
                return vo;
            }
            if (d.type ==5) {
                vo = d.borrowOutVo;
                vo.linkUnit = d.borrowOutVo.custom;
                return vo;
            }
        }
    </script>

</html:header>
<body>
<div id="printDiv">
</div>
</body>
</html>